"""
聊天系统Pydantic模型
"""
from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime


class ChatMessageCreate(BaseModel):
    """创建消息请求模型"""
    content: str = Field(..., description="消息内容")
    message_type: str = Field(default="text", description="消息类型")


class ChatMessageResponse(BaseModel):
    """消息响应模型"""
    id: int
    room_id: str
    sender_id: int
    sender_type: str
    message_type: str
    content: str
    created_at: datetime
    
    class Config:
        from_attributes = True


class ChatRoomResponse(BaseModel):
    """聊天房间响应模型"""
    id: int
    room_id: str
    user_id: int
    kefu_id: Optional[int] = None
    merchant_id: Optional[int] = None
    room_type: str = "kefu"
    attraction_id: Optional[int] = None
    order_id: Optional[int] = None
    is_active: bool
    created_at: datetime
    updated_at: datetime
    last_message: Optional[ChatMessageResponse] = None
    
    class Config:
        from_attributes = True


class MerchantRoomCreate(BaseModel):
    """创建商户聊天房间请求"""
    attraction_id: Optional[int] = None
    order_id: Optional[int] = None


class PlatformKefuRoomCreate(BaseModel):
    """创建平台客服聊天房间请求"""
    pass  # 平台客服房间不需要额外参数


class UserListResponse(BaseModel):
    """用户列表响应模型"""
    user_id: int
    username: str
    nickname: Optional[str]
    avatar: Optional[str]
    room_id: Optional[str]
    unread_count: int = 0
    last_message: Optional[ChatMessageResponse] = None

